package com.todod.base.module.base.service.wits8;

import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.common.util.object.BeanUtils;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.todod.base.module.base.controller.admin.wits8.vo.*;
import com.todod.base.module.base.dal.dataobject.wits8.WITS8DO;

import com.todod.base.module.base.dal.mysql.wits8.WITS8Mapper;

import static com.todod.base.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.todod.base.module.base.enums.ErrorCodeConstants.WITS8_NOT_EXISTS;

/**
 * WITS8生成的表 Service 实现类
 *
 * @author 超管儿
 */
@Service
@Validated
public class WITS8ServiceImpl implements WITS8Service {

    @Resource
    private WITS8Mapper wITS8Mapper;


    /**
     * 按照要求取一条最新数据
     */
    @Override
    public WITS8DO getNewOne(WITS8PageReqVO reqVO) {
        return wITS8Mapper.getNewOne(reqVO);
    }
    /**
     * 按照要求查询列表
     */
    @Override
    public List<WITS8DO>  getNewList(WITS8PageReqVO reqVO){
        return wITS8Mapper.getNewList(reqVO);
    }



    @Override
    public Long createWITS8(WITS8SaveReqVO createReqVO) {
        // 插入
        WITS8DO wITS8 = BeanUtils.toBean(createReqVO, WITS8DO.class);
        wITS8Mapper.insert(wITS8);
        // 返回
        return wITS8.getId();
    }

    @Override
    public void updateWITS8(WITS8SaveReqVO updateReqVO) {
        // 校验存在
        validateWITS8Exists(updateReqVO.getId());
        // 更新
        WITS8DO updateObj = BeanUtils.toBean(updateReqVO, WITS8DO.class);
        wITS8Mapper.updateById(updateObj);
    }

    @Override
    public void deleteWITS8(Long id) {
        // 校验存在
        validateWITS8Exists(id);
        // 删除
        wITS8Mapper.deleteById(id);
    }

    private void validateWITS8Exists(Long id) {
        if (wITS8Mapper.selectById(id) == null) {
            throw exception(WITS8_NOT_EXISTS);
        }
    }

    @Override
    public WITS8DO getWITS8(Long id) {
        return wITS8Mapper.selectById(id);
    }

    @Override
    public PageResult<WITS8DO> getWITS8Page(WITS8PageReqVO pageReqVO) {
        return wITS8Mapper.selectPage(pageReqVO);
    }


}